home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / ui / scrollfunc.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  7.7 KB  |  189 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from base.g import *
  5. from base import utils
  6. from qt import *
  7. from scrollview import ScrollView
  8. import os.path as os
  9. import os
  10.  
  11. class ScrollFunctionsView(ScrollView):
  12.     
  13.     def __init__(self, cmd_print, cmd_print_int, cmd_scan, cmd_scan_int, cmd_pcard, cmd_pcard_int, cmd_fax, cmd_fax_int, cmd_copy, cmd_copy_int, parent = None, form = None, name = None, fl = 0):
  14.         ScrollView.__init__(self, parent, name, fl)
  15.         self.cmd_print = cmd_print
  16.         self.cmd_print_int = cmd_print_int
  17.         self.cmd_scan = cmd_scan
  18.         self.cmd_scan_int = cmd_scan_int
  19.         self.cmd_copy = cmd_copy
  20.         self.cmd_copy_int = cmd_copy_int
  21.         self.cmd_pcard = cmd_pcard
  22.         self.cmd_pcard_int = cmd_pcard_int
  23.         self.cmd_fax = cmd_fax
  24.         self.cmd_fax_int = cmd_fax_int
  25.         self.form = form
  26.         self.ScanPixmap = QPixmap(os.path.join(prop.image_dir, 'scan_icon.png'))
  27.         self.PrintPixmap = QPixmap(os.path.join(prop.image_dir, 'print_icon.png'))
  28.         self.SendFaxPixmap = QPixmap(os.path.join(prop.image_dir, 'fax_icon.png'))
  29.         self.PhotoCardPixmap = QPixmap(os.path.join(prop.image_dir, 'pcard_icon.png'))
  30.         self.MakeCopiesPixmap = QPixmap(os.path.join(prop.image_dir, 'makecopies_icon.png'))
  31.  
  32.     
  33.     def setCmds(self, cmd_print, cmd_scan, cmd_pcard, cmd_fax, cmd_copy):
  34.         self.cmd_print = cmd_print
  35.         self.cmd_scan = cmd_scan
  36.         self.cmd_copy = cmd_copy
  37.         self.cmd_pcard = cmd_pcard
  38.         self.cmd_fax = cmd_fax
  39.  
  40.     
  41.     def fillControls(self):
  42.         ScrollView.fillControls(self)
  43.         if self.cur_device is not None and self.cur_device.supported and self.cur_device.device_state != DEVICE_STATE_NOT_FOUND:
  44.             if self.cmd_print_int:
  45.                 s = self._ScrollFunctionsView__tr('Print >>')
  46.             else:
  47.                 s = self._ScrollFunctionsView__tr('Print...')
  48.             self.addItem(self._ScrollFunctionsView__tr('<b>Print</b>'), self._ScrollFunctionsView__tr('Print documents or files.'), s, self.PrintPixmap, self.PrintButton_clicked)
  49.             if self.cur_device.scan_type:
  50.                 if self.cmd_scan_int:
  51.                     s = self._ScrollFunctionsView__tr('Scan >>')
  52.                 else:
  53.                     s = self._ScrollFunctionsView__tr('Scan...')
  54.                 self.addItem(self._ScrollFunctionsView__tr('<b>Scan</b>'), self._ScrollFunctionsView__tr('Scan a document or image.'), s, self.ScanPixmap, self.ScanButton_clicked)
  55.             
  56.             if self.cur_device.fax_type:
  57.                 if self.cmd_fax_int:
  58.                     s = self._ScrollFunctionsView__tr('Send PC Fax >>')
  59.                 else:
  60.                     s = self._ScrollFunctionsView__tr('Send PC Fax...')
  61.                 self.addItem(self._ScrollFunctionsView__tr('<b>Send PC Fax</b>'), self._ScrollFunctionsView__tr('Send a fax from the PC.'), s, self.SendFaxPixmap, self.SendFaxButton_clicked)
  62.             
  63.             if self.cur_device.copy_type:
  64.                 if self.cmd_copy_int:
  65.                     s = self._ScrollFunctionsView__tr('Make Copies >>')
  66.                 else:
  67.                     s = self._ScrollFunctionsView__tr('Make Copies...')
  68.                 self.addItem(self._ScrollFunctionsView__tr('<b>Make Copies</b>'), self._ScrollFunctionsView__tr('Make copies'), s, self.MakeCopiesPixmap, self.MakeCopiesButton_clicked)
  69.             
  70.             if self.cur_device.pcard_type:
  71.                 if self.cmd_pcard_int:
  72.                     s = self._ScrollFunctionsView__tr('Unload Photo Card >>')
  73.                 else:
  74.                     s = self._ScrollFunctionsView__tr('Unload Photo Card...')
  75.                 self.addItem(self._ScrollFunctionsView__tr('<b>Unload Photo Card</b>'), self._ScrollFunctionsView__tr('Copy images the device to the PC.'), s, self.PhotoCardPixmap, self.PCardButton_clicked)
  76.             
  77.         elif not self.cur_device.supported:
  78.             self.addGroupHeading('not_supported', self._ScrollFunctionsView__tr('ERROR: Device not supported.'))
  79.         else:
  80.             self.addGroupHeading('not_found', self._ScrollFunctionsView__tr('ERROR: Device not found. Please check connection and power-on device.'))
  81.  
  82.     
  83.     def PrintButton_clicked(self):
  84.         if self.cmd_print_int:
  85.             self.form.SwitchFunctionsTab('print')
  86.         else:
  87.             self.RunCommand(self.cmd_print)
  88.  
  89.     
  90.     def ScanButton_clicked(self):
  91.         if self.cmd_scan_int:
  92.             self.form.SwitchFunctionsTab('scan')
  93.         else:
  94.             self.RunCommand(self.cmd_scan)
  95.  
  96.     
  97.     def PCardButton_clicked(self):
  98.         if self.cur_device.pcard_type == PCARD_TYPE_MLC:
  99.             if self.cmd_pcard_int:
  100.                 self.form.SwitchFunctionsTab('pcard')
  101.             else:
  102.                 self.RunCommand(self.cmd_pcard)
  103.         elif self.cur_device.pcard_type == PCARD_TYPE_USB_MASS_STORAGE:
  104.             self.FailureUI(self._ScrollFunctionsView__tr("<p><b>Photocards on your printer are only available by mounting them as drives using USB mass storage.</b><p>Please refer to your distribution's documentation for setup and usage instructions."))
  105.         
  106.  
  107.     
  108.     def SendFaxButton_clicked(self):
  109.         if self.cmd_fax_int:
  110.             self.form.SwitchFunctionsTab('fax')
  111.         else:
  112.             self.RunCommand(self.cmd_fax)
  113.  
  114.     
  115.     def MakeCopiesButton_clicked(self):
  116.         if self.cmd_copy_int:
  117.             self.form.SwitchFunctionsTab('copy')
  118.         else:
  119.             self.RunCommand(self.cmd_copy)
  120.  
  121.     
  122.     def RunCommand(self, cmd, macro_char = '%'):
  123.         QApplication.setOverrideCursor(QApplication.waitCursor)
  124.         
  125.         try:
  126.             if len(cmd) == 0:
  127.                 self.FailureUI(self._ScrollFunctionsView__tr('<p><b>Unable to run command. No command specified.</b><p>Use <pre>Configure...</pre> to specify a command to run.'))
  128.                 log.error('No command specified. Use settings to configure commands.')
  129.             else:
  130.                 log.debug(utils.bold('Run: %s %s (%s) %s' % ('********************', cmd, self.cur_device.device_uri, '********************')))
  131.                 log.debug(cmd)
  132.                 cmd = []([ self.cur_device.device_vars.get(x, x) for x in cmd.split(macro_char) ])
  133.                 log.debug(cmd)
  134.                 path = cmd.split()[0]
  135.                 args = cmd.split()
  136.                 log.debug(path)
  137.                 log.debug(args)
  138.                 self.CleanupChildren()
  139.                 os.spawnvp(os.P_NOWAIT, path, args)
  140.         finally:
  141.             QApplication.restoreOverrideCursor()
  142.  
  143.  
  144.     
  145.     def CleanupChildren(self):
  146.         log.debug('Cleaning up child processes.')
  147.         
  148.         try:
  149.             os.waitpid(-1, os.WNOHANG)
  150.         except OSError:
  151.             pass
  152.  
  153.  
  154.     
  155.     def addItem(self, title, text, button_text, pixmap, button_func):
  156.         widget = self.getWidget()
  157.         self.addGroupHeading(title, title)
  158.         layout1 = QGridLayout(widget, 1, 3, 5, 10, 'layout1')
  159.         layout1.setColStretch(0, 1)
  160.         layout1.setColStretch(1, 10)
  161.         layout1.setColStretch(2, 2)
  162.         pushButton = QPushButton(widget, 'pushButton')
  163.         pushButton.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed, 0, 0, pushButton.sizePolicy().hasHeightForWidth()))
  164.         layout1.addWidget(pushButton, 0, 3)
  165.         icon = QLabel(widget, 'icon')
  166.         icon.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed, 0, 0, icon.sizePolicy().hasHeightForWidth()))
  167.         icon.setMinimumSize(QSize(32, 32))
  168.         icon.setMaximumSize(QSize(32, 32))
  169.         icon.setScaledContents(1)
  170.         layout1.addWidget(icon, 0, 0)
  171.         textLabel = QLabel(widget, 'textLabel')
  172.         textLabel.setAlignment(QLabel.WordBreak)
  173.         textLabel.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred, 0, 0, textLabel.sizePolicy().hasHeightForWidth()))
  174.         textLabel.setFrameShape(self.frame_shape)
  175.         layout1.addWidget(textLabel, 0, 1)
  176.         spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  177.         layout1.addItem(spacer1, 0, 2)
  178.         textLabel.setText(text)
  179.         pushButton.setText(button_text)
  180.         icon.setPixmap(pixmap)
  181.         self.connect(pushButton, SIGNAL('clicked()'), button_func)
  182.         self.addWidget(widget, str(title))
  183.  
  184.     
  185.     def __tr(self, s, c = None):
  186.         return qApp.translate('DevMgr4', s, c)
  187.  
  188.  
  189.